#!/bin/sh

##################
. /etc/profile
. ~/.bash_profile
##################

filename=hostlist_ecommerce

appdir=/root/log/ECommercePlatform 

cd $appdir

echo `pwd`

if [ `hostname` != "publicsyncserver" ];then

            	echo "please run this script at publicsyncserver's host"
		exit 1

fi




if [ ! -f ./$filename ];then

        echo " ./$filename no exit "
        exit 2

fi

read_date() {

read -p "Enter log date,one times one date,like this 2014-11-15:" -t 60  log_date
d[$n]=$log_date
read -p "weath are you contiue input:y/n " -t 60  choice

}

today_log() {

for i in `cat ./$filename`;do

        if [ `ping $i -c 4 |grep % | awk '{print $6}' | sed 's/%//g'` != 100 ];then 

                echo "$i network ok"
                ssh  $i  "bash" < ./today_log.sh
                sleep 2
        else

                echo "$i networt error"

        fi

done
}

history_log() {

echo -e "Enter log date,one date,like this 2014-11-15,if have two date 2014-11-15 2014-11-16 and so on \n"
read -p "Please input :" -t 120  log_date

echo "Please check it again: $log_date"

read -p "Are you sure(y/n):" check_it

if [ "$check_it" == "y" ];then 

sed -i "7c\a=( ${log_date} )" history_log.sh

	for i in `cat ./$filename`;do

        	if [ `ping $i -c 4 |grep % | awk '{print $6}' | sed 's/%//g'` != 100 ];then

                	echo "$i network ok"
	                ssh  $i  "bash" < ./history_log.sh
        	        sleep 2
        	else

                	echo "$i networt error"

       		fi

	done
else

	history_log
fi

}




echo -e "which type log do you want? \n 1):today log \n 2):history log \n 3):exit"

read -p "Enter you choice:" -t 5  log_type

case "$log_type" in
		1)
		today_log
		;;
		2)
		history_log
		;;
		3)
		exit 0
		;;
		*)
		echo "input error,please run it again!"
		;;

esac

exit 0


	
